function ajax({url="",data={},timeout=50000,type="get",success, error}={}){
    let str = ""
    for(let i in data){
        str += `${i}=${data[i]}&`
    }
    str = str.slice(0,-1);
    if(type.toLowerCase() === "get"){
        url += "?" + str;
    }
    const xhr = new XMLHttpRequest();
    xhr.timeout = timeout;
    xhr.open(type, url, true);
    xhr.onload = function(){
        if(xhr.status === 200){
            success && success(xhr.responseText);
        }else{
            error && error(xhr.status);
        }
    }
    xhr.ontimeout = function(){
        error && error("timeout");
        xhr.abort();
    }
    if(type.toLowerCase() === "get"){
        xhr.send();
    }else{
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.send(str);
    }
}